package com.yboot.stater.websocket.config;

import com.yboot.stater.websocket.core.api.DefaultDestinationResolveApi;
import com.yboot.stater.websocket.core.api.DestinationResolveApi;
import com.yboot.stater.websocket.core.api.SimpMessagingEnhanceTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.simp.SimpMessagingTemplate;

/**
 * WebSocket stomp 组件自动配置类
 *
 * @author yangcs
 * @date 2025/8/27 10:04
 */
public class StompToolConfiguration {

    /**
     * 推送目的地解析
     */
    @Bean
    @ConditionalOnMissingBean(DestinationResolveApi.class)
    public DestinationResolveApi destinationResolveApi() {
        return new DefaultDestinationResolveApi();
    }

    /**
     * 消息发送增强工具类
     */
    @Bean
    public SimpMessagingEnhanceTemplate simpMessagingEnhanceTemplate(SimpMessagingTemplate simpMessagingTemplate, DestinationResolveApi destinationResolveApi) {
        return new SimpMessagingEnhanceTemplate(simpMessagingTemplate, destinationResolveApi);
    }
}